using System.Linq;
using System;

using System.ComponentModel.Composition;
namespace Kooboo.Commerce.Repositories
{
 
    public partial class CommerceDataContext
    {
     

        //public IQueryable<Cart> Carts
        //{
        //    get
        //    {
        //        return from o in this.Orders.Where(i => i.OrderDate == null)
        //               join c in this.Customers
        //               on o.CustomerId equals c.Id into customers
        //               from i in customers.DefaultIfEmpty()
        //               select new Cart
        //               {
        //                   Address1 = o.Address1,
        //                   Address2 = o.Address2,
        //                   City = o.City,
        //                   Country = o.Country,
        //                   CountryCode = o.CountryCode,
        //                   Coupon = o.Coupon,
        //                   CreateDate = o.CreateDate == null ? DateTime.Now : o.CreateDate.Value,
        //                   CustomerId = o.CustomerId,
        //                   Customer = i,
        //                   EmailAddress = o.EmailAddress,
        //                   FirstName = o.FirstName,
        //                   Id = o.Id,
        //                   InsuredAmount = o.InsuredAmount,
        //                   InvoiceAddress1 = o.InvoiceAddress1,
        //                   InvoiceAddress2 = o.InvoiceAddress2,
        //                   InvoiceCity = o.InvoiceCity,
        //                   InvoiceCountryCode = o.InvoiceCountryCode,
        //                   InvoiceFirstName = o.InvoiceFirstName,
        //                   InvoiceLastName = o.InvoiceLastName,
        //                   InvoicePhone = o.InvoicePhone,
        //                   InvoicePostcode = o.InvoicePostcode,
        //                   InvoiceState = o.InvoiceState,
        //                   LastName = o.LastName,
        //                   OrderDiscount = o.OrderDiscount,
        //                   PaymentMethodCost = o.PaymentMethodCost,
        //                   PaymentName = o.PaymentName,
        //                   Phone = o.Phone,
        //                   Postcode = o.Postcode,
        //                   Remark = o.Remark,
        //                   ShippingCost = o.ShippingCost,
        //                   ShippingName = o.ShippingName,
        //                   ShippingOptionName = o.ShippingOptionName,
        //                   State = o.State,
        //                   SubTotal = o.SubTotal,
        //                   Total = o.Total,
        //                   TotalDiscount = o.TotalDiscount,
        //                   TotalTaxCost = o.TotalDiscount,
        //                   UseInvoiceAddress = o.UseInvoiceAddress,
        //               };   
        //    }
        //}

        //public IQueryable<CartItem> CartItems
        //{
        //    get
        //    {
        //        return this.OrderItems
        //            .Select(i => new CartItem
        //            {
        //                Discount = i.Discount,
        //                Id = i.Id,
        //                ProductId = i.ProductId,
        //                ProductName = i.ProductName,
        //                ProductVariationId = i.ProductVariationId,
        //                Quantity = i.Quantity,
        //                SKU = i.SKU,
        //                SubTotal = i.SubTotal,
        //                TaxCost = i.TaxCost,
        //                Total = i.Total,
        //                UnitPrice = i.UnitPrice,
        //                CartId = i.OrderId
        //            });
        //    }
        //}
    }


      
   
    public class DataReaderContext : CommerceDataContext
    {
        public DataReaderContext()
            : base(Kooboo.Commerce.Configuration.FindConnection())
        {
            this.ObjectTrackingEnabled = false;
        }
    }

   // [Export(typeof(DataReaderContext))]
    [Export(typeof(DataWriterContext))]
    public class DataWriterContext : DataReaderContext
    {
        public DataWriterContext()
            : base()
        {
            this.ObjectTrackingEnabled = true;
        }
    }

  
 


}
